﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Text;
using NW;

namespace PM_Remote
{
	public class PM_ServerClient : NWClient
	{
		ProcessMemory pm;
		public PM_ServerClient(ProcessMemory ipm, TcpClient iclient)
			: base(iclient)
		{
			pm = ipm;
		}
		protected override bool _ProcessMessage()
		{
			PM_Instr N = (PM_Instr)FetchInt32();
			switch (N)
			{
				case PM_Instr.OpenProcess:
					String proc = FetchStringS();
					Console.WriteLine("SRV: Open process '" + proc + "'");
					pm.AttachProcess(proc);
					SendPacket((int)PM_Instr.OpenProcess, pm.Handle);
					break;
				case PM_Instr.ReadBytes:
					int A = FetchInt32();
					int L = FetchInt32();
					Console.WriteLine("SRVCLI: request byte array (" + A + "," + L + ")");
					byte[] ret = new byte[] { 1, 6, 3, 7, 9, 2, 3 };
					//SendPacket((int)PM_Instr.ReadBytes, pm.ReadBytes(A, L));
					SendPacket((int)PM_Instr.ReturnBytes, ret);
					break;
				default:
					break;
			}
			return true;
		}
	}
}